<?php
session_start();
require_once("function.php");
require_once("Manager.php");
//require_once("RegularEmployee.php");

class deleteEmployeeController{
	
	
	function doesEmployeeHasPlanholder($empno){
		$con = connectToDB();
		$empno = mysql_real_escape_string($empno);
		
		//mysql_select_db("apodb", $con);

		$result = mysql_query("select * FROM planholder WHERE Account_Executive='$empno'");
		
		//$result = mysql_query("select * from employee where Emp_no = '$user' and Password = '$pass'");
		
		if(mysql_num_rows($result) >= 1)
		{
			return false;
		}
		else
		{
			return true;
		}
	}

	
	function updateEmployeeList(){
	
	//kay jeph
	}
	
	function sendDeleteEmployeeRequest($empno){
		$_SESSION['stat'] = "delete";	
		if(self::doesEmployeeHasPlanholder($empno)){
			$man = new Manager;
			$result = $man -> deleteEmployee($empno);

			if($result)
			{
				$_SESSION['msg'] = "Successfully deleted the employee";
			}
			else
			{
				$_SESSION['msg'] = "Failed to delete the employee";
			}
		}
		else
		{
			$_SESSION['msg'] = "Employee cannot be deleted<br/>Error:Employee still holds planholder/s";
		}
		
	}
}
$del = new deleteEmployeeController;
$eno = $_REQUEST['employee_no'];
$del-> sendDeleteEmployeeRequest($eno);


?>

